package araxy.blog.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    public static String parseTime(Date date) {
        return parseTime(date,"yyyy-MM-dd HH:mm:ss");
    }

    public static String parseTime(Date date,String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }


    public static Date parseTime(String date) throws ParseException {
        return parseTime(date,"yyyy-MM-dd HH:mm:ss");
    }

    public static Date parseTime(String date,String pattern) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.parse(date);
    }

    public static String getSysTime() {
        Date date = new Date();
        return parseTime(date);
    }

    public static String getSysTime(String pattern) {
        Date date = new Date();
        return parseTime(date,pattern);
    }

    public static Long getMinutesMS(Integer minute) {
        return 60*60*1000*(long)minute;
    }

    public static Long getHoursMS(Integer hour) {
        return 60*60*1000*(long)hour;
    }

    public static Long getDaysMS(Integer day) {
        return 24*60*60*1000*(long)day;
    }

    public static Long getSysTimeMS() {
        return System.currentTimeMillis();
    }

    public static Long offsetSecond(Date time,Long sec){
        Date target = new Date(time.getTime() + sec*1000);
        return target.getTime();
    }

    public static Long offsetSecond(Long time,Long sec){
        Date target = new Date(time + sec*1000);
        return target.getTime();
    }

    public static Long offsetHour(Date time,Long hour){
        return offsetSecond(time,60*60*hour);
    }

    public static Long offsetHour(Long time,Long hour){
        return offsetSecond(time,60*60*hour);
    }

    public static Long offsetDay(Date time,Long day){
        return offsetSecond(time,60*60*24*day);
    }

    public static Long offsetDay(Long time,Long day){
        return offsetSecond(time,60*60*24*day);
    }
}
